package com.ming.luckyDemo.controller;

import com.ming.luckyDemo.pojo.DO.UserInfoDO;
import com.ming.luckyDemo.pojo.entity.ResultBody;
import com.ming.luckyDemo.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.Objects;

/**
 * @author Tcm
 */
@RestController
public class AdminController {

    @Autowired
    private AdminService adminService;

    @PostMapping("/selectUserInfo")
    public ResultBody selectUserInfo(HttpServletRequest request){
        Cookie[] cookies = request.getCookies();
        if (Objects.isNull(cookies)){
            return ResultBody.error().message("未登录");
        }
        for (Cookie cookie : cookies) {
            UserInfoDO userInfoDO = adminService.login2(cookie.getName());
            return ResultBody.ok().message("用户信息").data("data",userInfoDO);
        }
        return ResultBody.error().message("cookie失败了");
    }
}
